package com.kate.mall.promotion.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import com.kate.mall.promotion.entity.FlashPromotionEntity;
import com.kate.mall.promotion.service.FlashPromotionService;
import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.R;
import io.swagger.annotations.Api;


/**
 * 限时购表
 *
 * @author kate-chan
 * @email 857782993@qq.com
 * @date 2022-12-26 16:35:22
 */
@Api(tags = "FlashPromotionController", description = "限时购表服务")
@RestController
@RequestMapping("promotion/flashpromotion")
public class FlashPromotionController {
    @Autowired
    private FlashPromotionService flashPromotionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("promotion:flashpromotion:list")
    @ApiOperation("获取所有限时购表信息")
    public R list(@RequestParam(required = false) Map<String, Object> params){
        PageUtils page = flashPromotionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("promotion:flashpromotion:info")
    @ApiOperation("获取指定id的限时购表详情")
    public R info(@PathVariable("id") Long id){
		FlashPromotionEntity flashPromotion = flashPromotionService.getById(id);

        return R.ok().put("flashPromotion", flashPromotion);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加限时购表信息")
    //@RequiresPermissions("promotion:flashpromotion:save")
    public R save(@RequestBody FlashPromotionEntity flashPromotion){
		flashPromotionService.save(flashPromotion);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id限时购表信息")
    //@RequiresPermissions("promotion:flashpromotion:update")
    public R update(@RequestBody FlashPromotionEntity flashPromotion){
		flashPromotionService.updateById(flashPromotion);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id限时购表信息")
    //@RequiresPermissions("promotion:flashpromotion:delete")
    public R delete(@RequestBody Long[] ids){
		flashPromotionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
